package service

import (
	"context"
	v1 "platform-sastay-file/api/platform/v1"
)

func (p *PlatformService) RegistryDomainNameMap(ctx context.Context, req *v1.RegistryDomainNameMapRequest) (*v1.RegistryDomainNameMapResponse, error) {
	domain, err := p.dnu.PutDomainNameMap(ctx, req.Ip, req.DomainName)
	if err != nil {
		return nil, err
	}
	return &v1.RegistryDomainNameMapResponse{
		Ip:         domain.IP,
		DomainName: domain.DomainName,
	}, nil
}

func (p *PlatformService) GetDomainName(ctx context.Context, req *v1.GetDomainNameRequest) (*v1.GetDomainNameResponse, error) {
	domainNameMap, err := p.dnu.GetDomainName(ctx, req.Ip)
	if err != nil {
		return nil, err
	}
	return &v1.GetDomainNameResponse{DomainName: domainNameMap.DomainName}, nil
}
